package javawork;
import java.lang.Math;

public class section9_9 {
    // 私有数据字段
    private int n;         // 边数，默认3
    private double side;   // 边长，默认1
    private double x;      // 中心x坐标，默认0
    private double y;      // 中心y坐标，默认0

    // 无参构造方法（默认值）
    public section9_9() {
        this.n = 3;
        this.side = 1;
        this.x = 0;
        this.y = 0;
    }

    // 构造方法（指定边数和边长，中心在(0,0)）
    public section9_9(int n, double side) {
        this.n = n;
        this.side = side;
        this.x = 0;
        this.y = 0;
    }

    // 构造方法（指定边数、边长和中心坐标）
    public section9_9(int n, double side, double x, double y) {
        this.n = n;
        this.side = side;
        this.x = x;
        this.y = y;
    }

    // 访问器和修改器方法
    public int getN() {
        return n;
    }

    public void setN(int n) {
        this.n = n;
    }

    public double getSide() {
        return side;
    }

    public void setSide(double side) {
        this.side = side;
    }

    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }

    // 计算周长
    public double getPerimeter() {
        return n * side;
    }

    // 计算面积（使用公式：Area = (n * s²) / (4 * tan(π/n))）
    public double getArea() {
        return (n * Math.pow(side, 2)) / (4 * Math.tan(Math.PI / n));
    }

    // 测试程序
    public static void main(String[] args) {
        // 创建三个RegularPolygon对象
        section9_9 polygon1 = new section9_9();
        section9_9 polygon2 = new section9_9(6, 4);
        section9_9 polygon3 = new section9_9(10, 4, 5.6, 7.8);

        // 输出第一个对象的周长和面积
        System.out.println("Polygon 1:");
        System.out.println("Perimeter: " + polygon1.getPerimeter());
        System.out.println("Area: " + polygon1.getArea() + "\n");

        // 输出第二个对象的周长和面积
        System.out.println("Polygon 2:");
        System.out.println("Perimeter: " + polygon2.getPerimeter());
        System.out.println("Area: " + polygon2.getArea() + "\n");

        // 输出第三个对象的周长和面积
        System.out.println("Polygon 3:");
        System.out.println("Perimeter: " + polygon3.getPerimeter());
        System.out.println("Area: " + polygon3.getArea());
    }
}